package com.briup.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.briup.common.bean.TblCategory;

/**
 * Servlet implementation class toUpdateCategoryInfo_Servlet
 */
@WebServlet("/jsp/manager/toUpdateCategoryInfo_Servlet")
public class toUpdateCategoryInfo_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public toUpdateCategoryInfo_Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = request.getParameter("category.id") ;
		TblCategory category = null ;
		List<TblCategory> categories = (List<TblCategory>) request.getSession().getAttribute("categories") ;
		for(int i = 0 ; i < categories.size() ; i ++) {
//			System.out.println(String.valueOf(categories.get(i).getId()));
			if (id.equals(String.valueOf(categories.get(i).getId()))) {
				category = categories.get(i) ;
//				System.out.println("***********************");
			}
		}
//		System.out.println(category);
		request.getSession().setAttribute("category", category);
		response.sendRedirect("updateCategory.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
